package dfs;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;

//全排列
public class FullPermutation {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        boolean[] isFlag = new boolean[nums.length];
        LinkedList<Integer> arrayList = new LinkedList<>();
        dfs(nums, isFlag, arrayList);
    }

    private static void dfs(int[] nums, boolean[] isFlag, LinkedList<Integer> arrayList) {
        if (arrayList.size() == nums.length) {
            System.out.println(arrayList);
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (!isFlag[i]) {
                isFlag[i] = true;
                arrayList.push(nums[i]);
                dfs(nums, isFlag, arrayList);
                isFlag[i] = false;
                arrayList.pop();
            }
        }
    }
}
